<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="模板编号">
              <j-input placeholder="模板编号" v-model="queryParam.templateNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="模板名称">
              <j-input placeholder="模板名称" v-model="queryParam.templateName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="模板类型">
              <j-dict-select-tag type="list" v-model="queryParam.templateType" style="width: 100%" placeholder="请选择模板类型" dictCode="template_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务分类">
              <business-category-name-select v-model="queryParam.bussinessName" placeholder="请选择业务分类" @back="businessCategoryHandle"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="允许添加子节点">
              <j-dict-select-tag type="list" v-model="queryParam.isAddChildNode" style="width: 100%" placeholder="请选择允许添加子节点" dictCode="yes_no"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经办人">
              <select-user-by-dep placeholder="请选择经办人" :multi="false" v-model="queryParam.proposer"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经办部门">
              <j-select-depart placeholder="请选择经办人部门" v-model="queryParam.proposerDeptId"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpProgressTemplate:add')">新增</a-button>
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('进度模板')" :disabled="isDisabledAuth('erpProgressTemplate:export')">导出</a-button>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpProgressTemplate:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">
                      <!-- {{ item.title }} -->
                      <ellipsis :length="15">{{ item.title }}</ellipsis>
                    </a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style="iconStyle"/></a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <span slot="notify" slot-scope="text, record">
          <a-icon
            title="催办提醒"
            v-if="record.taskUrge"
            theme="twoTone"
            twoToneColor="#eb2f96"
            @click="taskNotifyMe(flowCode,record.id)"
            type="notification"/>
          {{ text }}
        </span>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template >
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="edit"
              @click="handleEdit(record)"
              :disabled="isDisabledAuth('erpProgressTemplate:edit')"
            />
            <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
              <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="delete"
                :disabled="isDisabledAuth('erpProgressTemplate:delete')"/>
            </a-popconfirm>
          </template>
        </span>
        <a slot="templateName" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
      </a-table>
    </div>
    <erp-progress-template-modal ref="modalForm" @ok="modalFormOk"></erp-progress-template-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
  </a-card>
</template>
<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
  import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
  import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
  import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
  import ErpProgressTemplateModal from './modules/ErpProgressTemplateModal'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import SelectPersonInput from '@/views/scy/components/SelectPersonInput'
  import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
  import Ellipsis from '@/components/Ellipsis'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  export default {
    name: 'ErpProgressTemplateList',
    mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      BusinessCategoryNameSelect,
      SelectPersonInput,
      ErpProgressTemplateModal,
      BpmBizTaskDealModal,
      BpmProcessTrackModal,
      BizTaskNotifyModal,
      BizTaskNotifyMeModal,
      Ellipsis,
      SelectUserByDep
    },
    data () {
      return {
        description: '进度模板管理页面',
        // 表头
        columns: [],
        // 列设置
        settingColumns: [],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '模板编号',
            align: 'center',
            dataIndex: 'templateNo',
            width: 309,
            ellipsis: true
          },
          {
            title: '模板名称',
            align: 'center',
            dataIndex: 'templateName',
            width: 278,
            ellipsis: true,
            scopedSlots: { customRender: 'templateName' }
          },
          {
            title: '模板类型',
            align: 'center',
            dataIndex: 'templateType_dictText',
            width: 165,
            ellipsis: true
          },
          {
            title: '业务分类',
            align: 'center',
            dataIndex: 'bussinessType_dictText',
            width: 303,
            ellipsis: true
          },
          {
            title: '经办人',
            align: 'center',
            dataIndex: 'proposer_dictText',
            width: 96,
            ellipsis: true
          },
          {
            title: '经办部门',
            align: 'center',
            dataIndex: 'proposerDeptId_dictText',
            width: 211,
            ellipsis: true
          },
          {
            title: '允许添加子节点',
            align: 'center',
            dataIndex: 'isAddChildNode_dictText',
            width: 120,
            ellipsis: true
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: '/api/erp/progress/erpProgressTemplate/list',
          delete: '/api/erp/progress/erpProgressTemplate/delete',
          deleteBatch: '/api/erp/progress/erpProgressTemplate/deleteBatch',
          exportXlsUrl: '/api/erp/progress/erpProgressTemplate/exportXls',
          importExcelUrl: 'api/erp/progress/erpProgressTemplate/importExcel',
          bizCount: '/api/erp/progress/erpProgressTemplate/bizCount'
        },
        // 代码生成后需手动设置流程编码
        flowCode: 'onl_erp_progress_template',
        formUrl: 'erp/progress/modules/ErpProgressTemplateForm',
        formUrlMobile: '',
        dictOptions: {},
        superFieldList: []
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      businessCategoryHandle(obj) {
        console.log('data', obj)
        if (obj) {
          this.queryParam.bussinessType = obj.id;
        }
      },
      getDetail(id) {
        this.$router.push({
          path: `/erp/progress/ErpProgressTemplateListDetail/${id}`
        })
      },
      initDictConfig() {
      },
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'proposer', text: '经办人编号', dictCode: '' })
        fieldList.push({ type: 'sel_depart', value: 'proposer', text: '经办人部门ID' })
        fieldList.push({ type: 'string', value: 'templateNo', text: '模板编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'templateName', text: '模板名称', dictCode: '' })
        fieldList.push({ type: 'string', value: 'templateType', text: '模板类型', dictCode: 'template_type' })
        fieldList.push({ type: 'string', value: 'bussinessType', text: '业务分类', dictCode: 'ywfx_type' })
        fieldList.push({ type: 'Text', value: 'remark', text: '备注', dictCode: '' })
        fieldList.push({ type: 'string', value: 'bpmStatus', text: '流程状态', dictCode: 'bpm_status' })
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
